package com.guli.gulimall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;
import com.guli.gulimall.product.vo.AttrGroupVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.guli.gulimall.product.entity.AttrGroupEntity;
import com.guli.gulimall.product.service.PmsAttrGroupService;



/**
 * 属性分组
 *
 * @author ??
 * @email sunlightcs@gmail.com
 * @date 2022-05-30 19:43:59
 */
@RestController
@RequestMapping("product/attrgroup")
public class PmsAttrGroupController {
    @Autowired
    private PmsAttrGroupService pmsAttrGroupService;

    /**
     * 列表
     */
    @RequestMapping("/list/{catId}")
    public R list(@PathVariable("catId") Long catId,@RequestParam Map<String, Object> params){
        PageUtils page = pmsAttrGroupService.queryPage(catId,params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrGroupId}")
    public R info(@PathVariable("attrGroupId") Long attrGroupId){
		AttrGroupEntity pmsAttrGroup = pmsAttrGroupService.getById(attrGroupId);

        return R.ok().put("pmsAttrGroup", pmsAttrGroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrGroupEntity pmsAttrGroup){
		pmsAttrGroupService.save(pmsAttrGroup);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrGroupEntity pmsAttrGroup){
		pmsAttrGroupService.updateById(pmsAttrGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrGroupIds){
		pmsAttrGroupService.removeByIds(Arrays.asList(attrGroupIds));

        return R.ok();
    }

    //product/attrgroup/225/withattr?t=1654513312835
    @RequestMapping("/{catlogId}/withattr")
    public R withattrByCatlogId(@PathVariable("catlogId") Long catlogId){
        List<AttrGroupVo> attrGroupVos = pmsAttrGroupService.withattrByCatlogId(catlogId);
        return R.ok().put("data",attrGroupVos);
    }

}
